/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ticketonline.ui.servlet;

import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.context.ApplicationContext;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.web.context.support.WebApplicationContextUtils;
import ticketonline.entity.Customer;
import ticketonline.service.AppService;

/**
 *
 * @author amir
 */
public class DaftarCustomer extends HttpServlet{
    
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html");
        
	ApplicationContext ctx = WebApplicationContextUtils
		.getWebApplicationContext(req.getSession().getServletContext());
		
	AppService service = (AppService) ctx.getBean("appService");

	
        
        
        
        String output = "<html>";
        output += "<head>";
        output += "<title>Daftar Customer</title>";
        output += "</head>";
        output += "<body>";
        output += "<h1>Daftar Customer</h1>";
        output += "<table border=1>";
        output += "<tr> "
                + "<td>ID</td>"
                + "<td>Name</td>"
                + "<td>Address</td>"
                + "<td>Phone</td>"
                + "<td></td>"
                + "</tr>";
        
        List<Customer> cst= service.findAllCustomer();
        for(Customer c : cst){
            output += "<tr>"+
                        "<td>" + c.getCustID() + "</td>" +
                        "<td>" + c.getCustName() + "</td>" +
                        "<td>" + c.getCustAddress() + "</td>" +
                        "<td>" + c.getCustPhone() + "</td>" +
                        "<td><a href='edit.dot?id="+c.getCustID()+"'>edit</a>" +
			" | <a href='delete?id="+c.getCustID()+"'>delete</a></td>" +
                        "</tr>"; 
        }
        
        output += "</table>";
        output += "</body>";
        output += "</html>";
        
        resp.getWriter().print(output);
        resp.getWriter().close();
        
    }
    
    
}
